﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ePlanet.ArchiveMange.Enum;
using ePlanet.ArchiveBorrow.Models;
using Microsoft.Practices.Unity;
using ePlanet.ArchiveBorrow.Services;
using Web.SystemConfig.WorkFlow;

namespace Web.Views.ArchiveBorrow.ArchiveBorrowView
{
    public partial class ArchiveBorrowViewBasePage : PageBase
    {
        [Dependency]
        public IArchiveBorrowService m_IArchiveBorrowService
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Jump();
            }
        }

        private void Jump()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["DataID"]))
            {
                Guid archiveBorrowDataID = new Guid(Request.QueryString["DataID"]);
                ArchiveBorrowModel model = this.m_IArchiveBorrowService.GetSingleArchiveBorrowModelByDataID(archiveBorrowDataID);
                if (model != null && model.ARCHIVEBORROW.Rows.Count > 0)
                {
                    ArchiveTableEnum archiveType = (ArchiveTableEnum)(int)model.ARCHIVEBORROW[0].ARCHIVETYPEID;
                    this.Rediret(archiveType, Request.QueryString["DataID"]);
                }
                else
                {
                    Response.Write("该数据文档类型错误！");
                }
            }
            else
            {
                Response.Write("参数DataID不能为空！");
            }
        }

        private void Rediret(ArchiveTableEnum archiveType, string dataID)
        {
            string urlFormat = "{0}?ArchiveType="+((int)archiveType).ToString()+"&DataID=" + dataID;
            switch (archiveType)
            {
                case ArchiveTableEnum.Account:
                case ArchiveTableEnum.AccountI01:
                case ArchiveTableEnum.AccountI02:
                case ArchiveTableEnum.AccountI03:
                case ArchiveTableEnum.AccountI04:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowAccountView.aspx"));
                    break;
                case ArchiveTableEnum.AudioVedio:
                case ArchiveTableEnum.AudioVedioS01:
                case ArchiveTableEnum.AudioVedioS02:
                case ArchiveTableEnum.AudioVedioS03:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowAudioVedioView.aspx"));
                    break;
                case ArchiveTableEnum.BulidProject:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowBuildProjectView.aspx"));
                    break;
                case ArchiveTableEnum.CDKind:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowCDKindView.aspx"));
                    break;
                case ArchiveTableEnum.Document:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowDocumentView.aspx"));
                    break;
                case ArchiveTableEnum.Document_Archive_Vol:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowArchiveHistoryView.aspx"));
                    break;
                case ArchiveTableEnum.Document_Archive_Vol_File:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowArchiveHistoryView.aspx"));
                    break;
                case ArchiveTableEnum.Equipment:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowEquipmentView.aspx"));
                    break;
                case ArchiveTableEnum.OliSearch:
                case ArchiveTableEnum.OliSearchK01:
                case ArchiveTableEnum.OliSearchK02:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowOliSearchView.aspx"));
                    break;
                case ArchiveTableEnum.OliSearch_Zonghe_Vol:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowArchiveHistoryView.aspx"));
                    break;
                case ArchiveTableEnum.OliSearch_Zonghe_Vol_File:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowArchiveHistoryView.aspx"));
                    break;
                case ArchiveTableEnum.RealKind:
                case ArchiveTableEnum.RealKindR01:
                case ArchiveTableEnum.RealKindR02:
                case ArchiveTableEnum.RealKindR03:
                case ArchiveTableEnum.RealKindR04:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowRealKindView.aspx"));
                    break;
                case ArchiveTableEnum.Technology:
                    Response.Redirect(string.Format(urlFormat, "ArchiveBorrowTechnologView.aspx"));
                    break;
                default:
                    Alert("未知的文档类型！");
                    break;
            }
        }
    }
}